package servlet;

import model.Order;
import utils.JsonUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/order")
public class OrderServlet extends HttpServlet {
   @Override
   protected void doGet(HttpServletRequest req, HttpServletResponse resp)
       throws ServletException, IOException {
      resp.setContentType("application/json;charset=utf-8");

      // 购物车中的订单保存在session中
      Order order = (Order) req.getSession().getAttribute("order");

      // 将Order（购物车中的订单）转换为JSON字符串并输出
      resp.getWriter().println(JsonUtils.objectToString(order));
   }
}
